home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Readers / Gui4Cli / Tools / Read.gc < prev    next >
Text File  |  1997-12-02  |  5KB  |  221 lines

  1. G4C
  2.  
  3. ; A File Reader.
  4.  
  5. ; USE: GUILOAD guis:tools/read.gc FileName
  6.  
  7. ; ======================================================================
  8.  
  9. ;               Globals & system events
  10.  
  11. ; ======================================================================
  12.  
  13. WinBig 0 11 0 -13 "Loading..."    ; you may want to change the position
  14. WinType 11110001
  15. Varpath 'read.pop/read.srch'      ; use private vars & 2 other guis vars
  16.  
  17. xOnLoad filename
  18. filepath = ''
  19. gosub read.gc startup
  20.  
  21. xOnReload filename
  22. filepath = ''
  23. gosub read.gc startup
  24.  
  25. xROUTINE startup
  26. guiopen read.gc
  27. if $filename > ' '
  28.    ; OK file was passed
  29. elseif $*FILENAME > ' '         ; Global *FILENAME is for compatibility
  30. andifexists file $*FILENAME     ; with older versions.
  31.    filename  = $*FILENAME
  32.    delvar *FILENAME
  33.    gosub read.gc filechange
  34. else
  35.    gosub read.gc getfile
  36. endif
  37. gosub read.gc filechange
  38. extract filename path filepath
  39.  
  40.  
  41. ;-------> Upon closing, we quit so as not to use-up memory
  42.  
  43. xOnClose
  44. guiquit read.gc
  45.  
  46. ;------> on RMB we open our pop-up command window
  47.  
  48. xOnRMB 
  49. guiopen Read.pop
  50.  
  51. ;------> on quitting we also quit our other 2 guis
  52.  
  53. xonquit
  54. guiquit  read.srch
  55. guiquit  read.pop
  56.  
  57. ; ======================================================================
  58.  
  59. ;               The listview
  60.  
  61. ; ======================================================================
  62.  
  63. xListview 0 0 0 0 "" var "" 20 NUM
  64. GadID  1
  65. GadFont #mono 8 000
  66.  
  67.  
  68. ; ======================================================================
  69.  
  70. ;               Routines
  71.  
  72. ; ======================================================================
  73.  
  74. ;------> Routine to load & show file
  75.  
  76. xRoutine filechange filename            ; routine to load & show file
  77. if $filename > ' '
  78.    guiscreen read.gc front
  79.    SetWinTitle read.gc "Loading...."
  80.    lvuse read.gc 1                      ; choose our display listview
  81.    LVChange $filename
  82.    SetWinTitle read.gc '$filename                                '
  83. endif
  84. stop
  85.  
  86. ;------------> open a requester and get a file
  87.  
  88. xroutine getfile
  89. newname = ""
  90. ReqFile -1 -1 250 200 "Choose file" LOAD newname $filepath
  91. if $newname > ""
  92.    filename = $newname
  93.    extract filename path filepath
  94.    gosub read.gc filechange
  95. endif
  96.  
  97.  
  98. ;######################################################################
  99.  
  100.                 NEWFILE read.pop
  101. ;               Popup on RMB gui
  102.  
  103. ;######################################################################
  104.  
  105.  
  106. WINBIG 341 87 80 90 ""
  107. WinType 00001000
  108. winonmouse 30 7 
  109. varpath read.gc         ; use our main gui's vars
  110. box 0 0 0 0 out button
  111.  
  112. xOnRMB 
  113. guiclose Read.pop
  114.  
  115. xOnInactive
  116. guiclose Read.pop
  117.  
  118. xOnFail
  119. ezreq "Error during operation" OK ""
  120.  
  121. ;---------------> the Buttons
  122.  
  123. XBUTTON 0 0 80 15 Open
  124. guiclose Read.pop
  125. extract filename path read.gc/filepath
  126. ; use new filereq gui
  127. guiload guis:tools/filereq.gc read.gc filechange $read.gc/filepath 
  128. ; gosub read.gc getfile
  129.  
  130. XBUTTON 0 15 80 15 Edit
  131. guiclose Read.pop
  132. ifexists gui cedbar.gc                  ; This is for CEd (long story..)
  133.    guiscreen cedbar.gc front
  134.    sendrexx rexx_ced 'open new'
  135.    sendrexx rexx_ced 'open $filename'
  136.    sendrexx rexx_ced 'expand view'
  137. elseifexists variable *DEF.EDITOR
  138.    run '$*DEF.EDITOR $filename'         ; if called from a file manager
  139. else
  140.    run 'c:ed $filename'                 ; use ed if nothing defined
  141. endif
  142.  
  143. XBUTTON 0 30 80 15 Search
  144. guiclose read.pop
  145. guiopen  read.srch
  146.  
  147. XBUTTON 0 45 80 15 'Delete'
  148. action delete $filename req
  149.  
  150. XBUTTON 0 60 80 15 Quit
  151. guiclose read.pop
  152. guiquit  read.gc
  153.  
  154. ; set tb size..
  155.  
  156. XHSLIDER 1 75 37 14 "" tab 0 10 8 "%ld"
  157.  
  158. XBUTTON 58 75 22 14 "T"
  159. set tab $tab
  160. guiclose read.pop
  161. lvuse read.gc 1        ; reload listview
  162. LVChange $filename
  163.  
  164.  
  165. ;######################################################################
  166.                 NEWFILE read.srch
  167. ;               Gui to Search the file
  168.  
  169. ;######################################################################
  170.  
  171.  
  172. winbig -1 -1 300 32 'Enter Search string :'
  173. wintype 11110001
  174. varpath ''
  175.  
  176. xonopen         ; reset variables on opening
  177. mode = CI
  178. flag = 0
  179.  
  180. xTextIn  0 0 0 15 '' str '' 128
  181. gosub read.srch search
  182.  
  183. xCycler  0 17 150 14 '' mode    ; choose case sensitive/insen..
  184. cstr 'Ignore case' CI
  185. cstr 'Same case'   CS
  186.  
  187.  
  188. xButton 150 17 100 14 'Top'     ; go to top of lv
  189. flag = 0                        
  190. lvgo #0
  191. update read.gc 1 0
  192. setwintitle read.srch 'Enter search string :'
  193.  
  194.  
  195. xButton  250 17 50 14 >>
  196. gosub read.srch search
  197.  
  198.  
  199. xroutine search
  200. if $str = ''            ; no string entered 
  201.    stop
  202. endif
  203. lvuse read.gc 1         ; use the reader's listview
  204. if $flag = 0            ; flag=0 means this is the first time
  205.    flag = 1
  206.    lvsearch $str $mode first    ; Keywords such as mode (CI or CS), do
  207.                                 ; not get translated, but in lvsearch
  208.                                 ; it's an exception, so we can say $mode
  209. else
  210.    lvsearch $str $mode next
  211. endif
  212. if $$lv.line > ''               ; update to line found
  213.    update read.gc 1 $$lv.line
  214.    setwintitle read.srch 'Line $$lv.line'
  215. else
  216.    lvgo #0                      ; or else go top again
  217.    flag = 0
  218.    setwintitle read.srch 'Search Finished'
  219. endif
  220.  
  221.